<?php
	/**
	 * @package AmpleHarvest
	 */
	require_once 'TableHeader.php';

	/**
	 * @brief This class Describes the Query_History Table in the AmpleHarvest Database
	 *
	 * - Revision History
	 *  - 0.1
	 * 	 - <b>Date</b>: 30 MAR 2011
	 * 	 - <b>Author</b>: Randy Blancett
	 * 	  - Initial Version
	 *
	 * @author Randy Blancett
	 * @version 0.1
	 * @ingroup code classes table
	 */
	class cTABLE_Drop_Down extends cTable
	{
		const C_STR_DROPDOWN_QUERY_SCHEDULE = "C1645168-1F6B-4439-91D7-25460E481561";
		const C_STR_DROPDOWN_SORT_OPTIONS = "3B06F406-D078-4182-ACA2-B65882E0C1DD";
		const C_STR_DROPDOWN_SORT_DIRECTION = "DDBA0013-3655-425B-88AE-067DE61FC30A";
		const C_STR_DROPDOWN_SEARCH_LAYOUT = "7A9B0DB7-E7B2-44D6-9624-9B6699EA660C";
		const C_STR_DROPDOWN_HR_STATUS = "4A669C97-65F0-4E89-B818-9B4249EC1E13";
		const C_STR_DROPDOWN_HR_TYPE = "7979D1A5-3758-4C94-8D5E-AE6DAF5A841A";
		const C_STR_DROPDOWN_HR_FREQUENCY = "A2D0E0B8-88FA-4D8C-B162-B5F90B32FCB8";
		const C_STR_DROPDOWN_DEFAULT_YESNO = "7C4348E5-09C8-4073-884C-ACB848D43730";
		/**
		 * @{
		 * @name Columns
		 */
		public $m_int_COL_ID = null;
		public $m_int_COL_Name = null;
		/**
		 * @}
		 */

		/**
		 * This constructor sets all the required column data
		 */
		public function __construct()
		{
			$this->m_str_TableName = "drop_down";
			$this->set_Engine(self::C_STR_ENGINE_INNODB);

			//Create Column Objects
			$obj_COL_ID = new cColVarChar("id");
			$obj_COL_ID->set_Length(36);
			$obj_COL_ID->set_Index(abs_Column::c_int_INDEX_PRIMARY);
			$obj_COL_ID->set_Comment("This column holds the ID of the Drop Down.");
			$obj_COL_ID->set_Editable(false);
			$obj_COL_ID->set_Label("ID");

			$obj_COL_Name = new cColVarChar("name");
			$obj_COL_Name->set_Length(50);
			$obj_COL_Name->set_Comment("This column holds the name of the item in the drop down.");
			$obj_COL_Name->set_Label("Name");

			//Set up connection
			$this->m_obj_Connection = new cConnection("AmpleHarvest", "admin");

			//Activate all Debug options
			$this->m_obj_Connection->set_DebugLevel(cLog_Connection_Debug::c_int_LEVEL_HIDDEN);
			$this->m_obj_Connection->set_LogLevel(cLog_Connection::c_int_LEVEL_BASIC);
			//$this->m_obj_Connection->activate_Logging();
			//$this->m_obj_Connection->activate_LogDebug();
			//$this->m_obj_Connection->activate_ScreenDebug();

			$this->m_int_COL_ID = $this->add_Column($obj_COL_ID);
			$this->m_int_COL_Name = $this->add_Column($obj_COL_Name);
		}

		public function insert_DefaultData()
		{
			$this->set_id(self::C_STR_DROPDOWN_QUERY_SCHEDULE);
			$this->set_name("Query Schedule Drop Down");

			$this->save_Data2DB();

			$this->set_id(self::C_STR_DROPDOWN_SORT_OPTIONS);
			$this->set_name("Query Standard Sort Drop Down");

			$this->save_Data2DB();

			$this->set_id(self::C_STR_DROPDOWN_SORT_DIRECTION);
			$this->set_name("Query Standard Sort Direction Drop Down");

			$this->save_Data2DB();

			$this->set_id(self::C_STR_DROPDOWN_HR_STATUS);
			$this->set_name("Harvest Request Status Drop Down.");

			$this->save_Data2DB();

			$this->set_id(self::C_STR_DROPDOWN_HR_TYPE);
			$this->set_name("Harvest Request Type Drop Down.");

			$this->save_Data2DB();

			$this->set_id(self::C_STR_DROPDOWN_HR_FREQUENCY);
			$this->set_name("Harvest Request Frequency Drop Down.");

			$this->save_Data2DB();

			$this->set_id(self::C_STR_DROPDOWN_DEFAULT_YESNO);
			$this->set_name("Default Yes-No Dropdown.");

			$this->save_Data2DB();

			$this->set_id(self::C_STR_DROPDOWN_SEARCH_LAYOUT);
			$this->set_name("List of posible Search Layouts.");

			$this->save_Data2DB();

			return true;
		}
		/**
		 * Inserts default information into the table this adds required information
		 * that is needed for AmpleHarvest to function.
		 * @deprecated
		 */
		public function insert_DetaultData()
		{
			return $this->insert_DefaultData();
		}

		/**
		 * Returns if the id is a valid and existing ID
		 * @param string $str_User_ID ID of the Page to check (GUID)
		 * @return boolean true if valid false if not
		 */
		public function validate_ID($str_ID)
		{
			// ensure that there is an ID passed and that it is a valid GUID
			if (!empty($str_ID) && preg_match(self::c_REG_GUID_VALID, $str_ID))
			{
				$this->clear_Query();
				$this->add_ColumnQuery($this->m_int_COL_ID, $str_ID);
				if ($this->do_Search() > 0)
				{
					return true;
				}
			}
			return false;
		}

		/**
		 * Loads information into object from Database based on ID passed
		 * @param string $str_ID ID of the id to check (int)
		 * return boolean true if loaded false if not
		 */
		public function load_DataFromID($str_ID)
		{
			$this->clear();

			if ($this->validate_ID($str_ID))
			{
				$this->clear_Query();
				$this->add_ColumnQuery($this->m_int_COL_ID, $str_ID);
				if ($this->do_Search() > 0)
				{
					$obj_RS = $this->get_ResultSet();
					if ($obj_RS[0])
					{
						$this->load_DataFromArray($obj_RS[0]);
						return true;
					}
				}
			}
			return false;
		}

		/**
		 * Saves Information to the Database
		 */
		public function save_Data2DB()
		{
			if ($this->validate_ID($this->get_id()))
			{
				return $this->update_Data2DB();
			}
			else
			{
				return $this->insert_Data2DB();
			}
		}
		/**
		 * This function is used to update data that is already in the database
		 */
		public function update_Data2DB()
		{
			//			$this->clear_Update();
			//			$this->add_ColumnQuery($this->m_int_COL_ID, $this->get_id());

			return parent::update_Data2DB();
		}
		/**
		 * This function is used to insert Data into the database
		 */
		public function insert_Data2DB()
		{
			//			$this->set_id($this->create_GUID());
			//			$this->set_date(date_format(new datetime(), "Y-m-d H:i:s"));
			return parent::insert_Data2DB();
		}

	}
?>
